/**
 * njsvm  session
 *
 * $Id: session.js 6 2011-07-12 08:32:51Z leizongmin@gmail.com $
 * @author 老雷 <leizongmin@gmail.com>
 * @version 0.22
 * @date 2011-07-12 09:36:24
 */
 
var	events	= require('events'),
	path	= require('path'),
	util	= require('util'),
	fs		= require('fs'),
	vm		= require('vm'),
	config	= require('./config'),
	njsmodule = require('./njsmodule');
 
 
Session = function () {
	this.timestamp = new Date().getTime();
}
util.inherits(Session, events.EventEmitter);



/** 所有函数均通过session对象来提供 */
// 调试输出
var debug = function (x) {
	console.log('[debug] ' + x);
}
Session.prototype.debug = debug;

// 结束会话
Session.prototype.end = function () {
	this.emit('end');
}

// require函数  如果出错，则返回string格式的出错描述
Session.prototype.require = njsmodule.require;

// setTimeout函数
Session.prototype.setTimeout = setTimeout;

// clearTimeout函数
Session.prototype.clearTimeout = clearTimeout;

// setInterval函数
Session.prototype.setInterval = setInterval;

// clearInterval函数
Session.prototype.clearInterval = clearInterval;

// console
Session.prototype.console = console;

// Buffer
Session.prototype.Buffer = Buffer;


// 拼接POST数据块
Session.prototype._postData = function (chunk) {
	debug('POST data: ' + (chunk.length / 1024) + 'KB');
}



/** 模块输出 */
exports.Session = Session;



// 测试
// console.log(findModulePath(__dirname + '/njsfd'));